package com.training.admin.dao;

import java.util.List;
import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.training.admin.entity.project.ProjectPhase;
import com.training.admin.entity.project.ProjectPhaseCourse;
/**
 * 
 * @author Rockett
 *
 */
@Dao("hibernate")
public interface ProjectPhaseCourseDao {
	
	/**
	 * 
	 * @param projectPhaseId
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false and projectPhase.id =:projectPhaseId")
	public List<ProjectPhaseCourse> listByProjectPhaseId(@Variable("projectPhaseId") Long projectPhaseId);
	/**
	 * 
	 * @param projectPhaseId
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false and projectPhase.id =:projectPhaseId and course.id =:courseId")
	public List<ProjectPhaseCourse> listByProjectPhaseAndCourseId(@Variable("projectPhaseId") Long projectPhaseId,@Variable("courseId") Long courseId);
	
	/**
     * 
     * @param projectPhaseId
     * @return
     */
    @Query("FROM ProjectPhaseCourse WHERE disabled = false and projectPhase.id =:projectPhaseId and course.id =:courseId")
    public ProjectPhaseCourse loadByProjectPhaseAndCourseId(@Variable("projectPhaseId") Long projectPhaseId,@Variable("courseId") Long courseId);
	
	/**
	 * 项目课程统计
	 * @param projectId
	 * @return
	 */
	@Query("select count(*),sum(course.hour) FROM ProjectPhaseCourse WHERE disabled = false and projectPhase.project.id =:projectId")
	public Object[] statisticsByProjectId(@Variable("projectId") Long projectId);

	/**
	 * @param projectPhases
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false AND projectPhase in (:projectPhases)")
	public List<ProjectPhaseCourse> list(@Variable("projectPhases") List<ProjectPhase> projectPhases);
	
	/**
	 * 
	 * @param projectIds
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false AND projectPhase.disabled = false AND course.disabled = false AND course.id in (:courseIds) AND projectPhase.project.id in (:projectIds)")
	public List<ProjectPhaseCourse> listByProjects(@Variable("projectIds") List<Long> projectIds, @Variable("courseIds") List<Long> courseIds);
	
	/**
	 * @param projectPhase
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false AND projectPhase = :projectPhase")
    public List<ProjectPhaseCourse> listByProjectPhase(@Variable("projectPhase") ProjectPhase projectPhase);
    
	/**
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false")
	public List<ProjectPhaseCourse> listProjectPhaseCourse();
	
	/**
	 * list by trainer
	 * @param trainerId
	 * @return
	 */
	@Query("FROM ProjectPhaseCourse WHERE disabled = false AND trainer.id =:trainerId")
	public List<ProjectPhaseCourse> listByTrainer(@Variable("trainerId") Long trainerId);

}
